package com.leyou.user.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.SecureRandom;

@Data
@Configuration
@ConfigurationProperties(prefix = "ly.encode.crypt")
public class PassWordConfig {

    private int strength; //加密的层数
    private String secret;//随机的加盐值

    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        //利用秘钥生成随机安全码
        SecureRandom secureRandom = new SecureRandom(secret.getBytes());
        //初始化BCryptPasswordEncoder
        return  new BCryptPasswordEncoder(strength,secureRandom);
    }
}
